Fix inpainting robustness: correct NaN propagation and fill value#146
Open
simone-silvestri wants to merge 3 commits intomainfrom
Open
Fix inpainting robustness: correct NaN propagation and fill value#146simone-silvestri wants to merge 3 commits intomainfrom
simone-silvestri wants to merge 3 commits intomainfrom
Conversation
Two bugs in the nearest-neighbor inpainting algorithm: 1. `_propagate_field!` used `value == 0` instead of `donors == 0` to detect cells with no valid neighbors. When valid neighbors average to zero (e.g. temperature near 0°C), cells were incorrectly marked as NaN. 2. `_fill_nans!` converted remaining NaN cells to 0, which is catastrophic for fields like salinity (~34 psu). Now fills with the mean of valid interior data instead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_propagate_field!to usedonors == 0instead ofvalue == 0for detecting cells with no valid neighbors — the old check incorrectly marked cells as NaN when valid neighbors averaged to zero_fill_nans!to fill remaining NaN with the field mean instead of 0 — using 0 is catastrophic for fields like salinity (~34 psu) and can destabilize simulationsMWE demonstrating the bugs
Test plan
donors == 0fix: zero-average neighbors correctly inpaint to 0.0_fill_nans!fix: unreachable cells fill with field mean (~34) instead of 0test_inpainting_algorithmpasses with updated expectations🤖 Generated with Claude Code